<?php

namespace app\common\model\purchase;

use think\Model;


class Retreat extends Model
{

    

    

    // 表名
    protected $name = 'purchase_retreat';
    
    // 自动写入时间戳字段
    protected $autoWriteTimestamp = 'int';

    // 定义时间戳字段名
    protected $createTime = 'createtime';
    protected $updateTime = false;
    protected $deleteTime = false;

    // 追加属性
    protected $append = [
        'collectiontime_text'
    ];


    public function retreat_status(){
        return array(
            1=>'待审核',
            2=>'待出库',
            3=>'待确认',
            4=>'完成',
            5=>'驳回',
            6=>'强制中止',
        );
    }





    public function getCollectiontimeTextAttr($value, $data)
    {
        $value = $value ? $value : (isset($data['collectiontime']) ? $data['collectiontime'] : '');
        return is_numeric($value) ? date("Y-m-d H:i:s", $value) : $value;
    }

    protected function setCollectiontimeAttr($value)
    {
        return $value === '' ? null : ($value && !is_numeric($value) ? strtotime($value) : $value);
    }


    public function purchaseenter()
    {
        return $this->belongsTo('app\common\model\purchase\Enter', 'purchase_enter_id', 'id', [], 'LEFT')->setEagerlyType(0);
    }


    public function purchaseorder()
    {
        return $this->belongsTo('app\common\model\purchase\Order', 'purchase_order_id', 'id', [], 'LEFT')->setEagerlyType(0);
    }


    public function storehouse()
    {
        return $this->belongsTo('app\common\model\Storehouse', 'storehouse_id', 'id', [], 'LEFT')->setEagerlyType(0);
    }


    public function supplier()
    {
        return $this->belongsTo('app\common\model\supplier\Supplier', 'supplier_id', 'id', [], 'LEFT')->setEagerlyType(0);
    }
}
